<?php
/**
 * Author:  ewen
 */

namespace app\admin\controller;

use app\common\model\Common;
use app\common\model\XkSystemSetting;
use think\Controller;
use think\Session;

class Base extends Controller
{

    protected $nowLang;

    /**
     * 析构函数
     */
    function __construct()
    {
        Session::start();
        header("Cache-control: private");  // history.back返回后输入框值丢失问题
        parent::__construct();

        //  网站设置
        if (cache(Common::CACHE_SYSTEM_BASE_INFO)) {
            $systemSetting = cache(Common::CACHE_SYSTEM_BASE_INFO);
        } else {
            $systemSetting = XkSystemSetting::get(1);
            cache('systemSetting', $systemSetting);
        }
        $this->assign('systemSetting', $systemSetting);

        //  语言包
        $lang = new GetLang();
        $now_lang = $lang->get_lang();//获取当前语言
        $this->nowLang = $now_lang;
        $this->assign('now_lang', $now_lang);
        if ($now_lang == 'zh-cn') {
            $now_lang = 'en-us';
        } elseif ($now_lang == 'en-us') {
            $now_lang = 'zh-cn';
        }
        $this->assign('set_lang', $now_lang);
    }

    /*
     * 初始化操作
     */
    public function _initialize()
    {
        if (!in_array(ACTION_NAME, [
            'login',
            'logout',
            'verifycode',
            'checkverifycode'
        ])) {
            //  管理员信息
            if (session('adminInfo')) {
                $adminInfo = session('adminInfo');
                $this->assign('adminInfo', $adminInfo);
            } else {
                $this->error(lang('please log in'), 'Admin/login');
            }
        }

    }


}